package com.ming.demo.web.impl;

import com.ming.demo.bean.Result;
import com.ming.demo.service.LoginService;
import com.ming.demo.utils.JwtTokenUtil;
import com.ming.demo.web.LoginController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/login")
public class LoginControllerImpl implements LoginController {
    @Autowired
    private LoginService loginService;

    @Override
    @RequestMapping("/getToken")
    public Result<String> getToken(String code, HttpServletResponse response) {
        String token = loginService.getToken(code);
        Result result = new Result();
        result.setCode("200");
        result.setData(token);
        response.setHeader(JwtTokenUtil.AUTH_HEADER_KEY, JwtTokenUtil.TOKEN_PREFIX + token);
        return result;
    }


    @Override
    @RequestMapping("/tokenTest")
    public void testToken(String token) {
        loginService.testToken(token);
    }
}
